"""
提供对房屋的各种操作
"""
from my_tools import *

houses = [{"id":1,"name":"tim","phone":"113","address":"广东","rent":800,"status":"未出租"}]
id_counter = 1



def main_menu():
    """
    显示主菜单
    :return:
    """
    print()
    print("房屋出租系统".center(32,"="))
    print("\t\t\t1 新增房源")
    print("\t\t\t2 查找房源")
    print("\t\t\t3 删除房源信息")
    print("\t\t\t4 房屋列表")
    print("\t\t\t5 退出")


def list_house():
    """
    显示房屋列表
    :return:
    """
    print("房屋列表".center(30,"="))
    print("编号\t\t房主\t\t电话\t\t地址\t\t月租\t\t状态(未出租/已出租)")
    for house in houses:
        for val in house.values():
            print(val,end="\t\t")
        print()
    print("房屋信息显示完毕".center(30,"="))

def add_house():
    """
    添加房屋信息
    :return:
    """
    print("添加房屋".center(30,"="))
    name = input("姓名: ")
    phone = input("电话: ")
    address = input("地址: ")
    rent = int(input("租金: "))
    status = input("状态: ")
    global id_counter
    id_counter += 1
    house = {"id":id_counter,"name":name,"phone":phone,"address":address
        ,"rent":rent,"status":status}
    houses.append(house)
    print("房屋添加成功".center(30,"="))


def del_house():
    print("删除房屋信息".center(30,"="))

    del_id = int(input("请输入待删除房屋的编号(-1退出)"))
    if del_id == -1:
        print("取消删除".center(30, "="))
        return
    key = read_confirm_select()
    if key == 'y':
       house = find_by_id(del_id)
       if house:
           houses.remove(house)
           print("删除成功".center(30, "="))
       else:
           print("房屋信息不存在".center(30, "="))


    else:
        print("取消删除".center(30, "="))


def find_by_id(find_id):
    """
    根据id查找房屋
    :param find_id:
    :return:
    """
    for house in houses:
        if house.get("id") == find_id:
            return house


def exit_sys():
    """
    退出系统
    :return:
    """
    key = read_confirm_select()
    if key == 'y':
        return True
    else:
        return False

def find_house_by_id():
   find_id = int(input("输入id: "))
   house = find_by_id(find_id)
   if house:
       print(f"编号: {house['id']}\t\t房主: {house['name']}\t\t电话: {house['name']}\t\t地址: {house['address']}\t\t月租: {house['rent']}\t\t状态(未出租/已出租): {house['status']}")
   else:
       print("不存在")